home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / Prog / T / TIFF Code.sit / tools.c / tools.c
Encoding:
C/C++ Source or Header  |  1987-12-16  |  3.0 KB  |  152 lines  |  [TEXT/MPS ]

  1. /* Standard C Include files */
  2. /* #include "CType.h" */
  3. /* #include "ErrNo.h" */
  4. /* #include "FCntl.h" */
  5. /* #include "IOCtl.h" */
  6. /* #include "Math.h" */
  7. /* #include "SetJmp.h" */
  8. /* #include "Signal.h" */
  9. /* #include "StdIO.h" */
  10. /* #include "String.h" */
  11.  
  12. /* Primary Interface Files */
  13. #include "Types.h"
  14. #include "Resources.h"
  15. #include "Quickdraw.h"
  16. /* #include "Windows.h" */
  17. /* #include "OSUtils.h" */
  18.  
  19. /* Commonly Included files */
  20. /* #include "ToolUtils.h" */
  21. #include "TextEdit.h"
  22. /* #include "Controls.h" */
  23.  
  24. /* Other Interface files */
  25. /* #include "AppleTalk.h" */
  26. /* #include "CursorCtl.h" */
  27. /* #include "Desk.h" */
  28. /* #include "DeskBus.h" */
  29. /* #include "Devices.h" */
  30. #include "Dialogs.h"
  31. /* #include "DiskInit.h" */
  32. /* #include "Disks.h" */
  33. /* #include "ErrMgr.h" */
  34. #include "Errors.h"
  35. /* #include "Events.h" */
  36. #include "Files.h"
  37. /* #include "Fonts.h" */
  38. /* #include "Graf3D.h" */
  39. /* #include "Lists.h" */
  40. #include "Memory.h"
  41. /* #include "Menus.h" */
  42. #include "Packages.h"
  43. /* #include "Palette.h" */
  44. /* #include "Perf.h" */
  45. /* #include "Picker.h" */
  46. /* #include "Printing.h" */
  47. /* #include "Retrace.h" */
  48. /* #include "ROMDefs.h" */
  49. /* #include "SANE.h" */
  50. #include "Scrap.h"
  51. /* #include "Script.h" */
  52. /* #include "SCSI.h" */
  53. /* #include "SegLoad.h" */
  54. /* #include "Serial.h" */
  55. /* #include "Slots.h" */
  56. /* #include "Sound.h" */
  57. /* #include "Start.h" */
  58. /* #include "Strings.h" */
  59. /* #include "Time.h" */
  60. /* #include "Traps.h" */
  61. /* #include "Values.h" */
  62. /* #include "VarArgs.h" */
  63. /* #include "Video.h" */
  64.  
  65. /* Application-specific Include files */
  66. #include "::TiffLibrary:TIFFLib.h"
  67. #include "sample.h"
  68. #include "messages.h"
  69.  
  70. struct {
  71.     unsigned char length;
  72.     unsigned char text[1];
  73. } noString = {
  74.     0,
  75.     ""
  76. };
  77.  
  78. void ErrorMessage(stringResourceID)
  79. Int16 stringResourceID;
  80. {
  81.     Handle strHandle;
  82.     
  83.     strHandle = GetResource('STR ', stringResourceID);
  84.     if (ResError() != noErr)
  85.         return;
  86.     if (strHandle == nil) {
  87.         LoadResource(strHandle);
  88.         if (ResError() != noErr)
  89.             return;
  90.     }
  91.     HLock(strHandle);
  92.     PARAMTEXT(&(**strHandle), &noString, &noString, &noString);
  93.     HUnlock(strHandle);
  94.     Alert(ERRORALERT, nil);
  95. }
  96.  
  97. Ptr MyNewPtr(size)
  98. Int32 size;
  99. {
  100.     Ptr p;
  101.     p = NewPtr(size);
  102.     if (MemError() != noErr) {
  103.         ErrorMessage(BADMEMORY);
  104.         p = nil;
  105.     }
  106.     return(p);
  107. }
  108.  
  109. Handle MyNewHandle(size)
  110. Int32 size;
  111. {
  112.     Handle p;
  113.     p = NewHandle(size);
  114.     if (MemError() != noErr) {
  115.         ErrorMessage(BADMEMORY);
  116.         p = nil;
  117.     }
  118.     return(p);
  119. }
  120.  
  121. void MyDisposPtr(pPtr)
  122. Ptr *pPtr;
  123. {
  124.     if (*pPtr != nil)
  125.         DisposPtr(*pPtr);
  126.     *pPtr = nil;
  127. }
  128.  
  129. void MyDisposHandle(pHandle)
  130. Ptr *pHandle;
  131. {
  132.     if (*pHandle != nil)
  133.         DisposPtr(*pHandle);
  134.     *pHandle = nil;
  135. }
  136.  
  137. #ifdef DEBUG
  138. void DebugMessage(pFormat, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
  139. register char *pFormat;                /* pointer to printf format string */
  140. long arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
  141. {
  142.     register char *p;
  143.     register int i;
  144.     static Str255 DbgString;
  145.     
  146.     sprintf(DbgString.text, pFormat, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
  147.     DbgString.length = strlen(DbgString.text);
  148.     PARAMTEXT(&DbgString, &noString, &noString, &noString);
  149.     Alert(ERRORALERT, nil);
  150. }
  151. #endif
  152.